package com.yy.jhl.ui.manager.presenter;

import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.ui.manager.contract.SealBoxAddContract;

import org.json.JSONException;
import org.json.JSONObject;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;

/**
 * Created by libingn on 2017/12/22.
 */

public class SealBoxAddPresenter extends SealBoxAddContract.Presenter {
    @Override
    public void modifyPackage(String package_id,String batch_id, String pack_num,String items) {
        RequestBody requestBody = new FormBody.Builder()
                .add("package_id", package_id)
//                .add("company_id", company_id)
                .add("batch_id", batch_id)
                .add("pack_num", pack_num)
//                .add("ver", ver+"")
                .add("items", items)
                .build();
        mRxManage.addSubscription(Api.getDefault().modifyPackage(requestBody), new RxSubscriber<ResponseBody>(mContext,true) {
            @Override
            protected void _onNext(String result) {
                try {
                    JSONObject object = new JSONObject(result);
                    mView.modifyPackageSuccess(object.optString("package_id"),object.optString("pack_num"),object.optString("is_finish"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            protected void _onError(String message) {
                mView.modifyPackageFail();
            }
        });
    }
}
